#pragma once

#define Die(v) exit(v)
#define CONV(v) (struct sockaddr *)v
enum Code
{
    SOCKET_ERROR = 1,
    BIND_ERROR,
    LISTEN_ERROR,
    USAGE_ERROR,
};
const int gdefaultsockfd = -1;
const int gbacklog = 8;

bool ParseOneLine(std::string &str, std::string *out, const std::string sep)
{
    // 1.正常字符串
    // 2.out 空串&&返回值为false
    // 3.out 空串&&返回值为true
    auto pos = str.find(sep);
    if (pos == std::string::npos)
    {
        return false;
    }
    *out = str.substr(0, pos);
    str.erase(0, pos + sep.size());
    return true;
}
bool SplitString(const std::string &str, const std::string &sep, std::string *k, std::string *v)
{
    // xx:xx
    int pos = str.find(sep);
    if (pos == std::string::npos)
    {
        return false;
    }
    *k = str.substr(0, pos);
    *v = str.substr(pos + sep.size());
    if ((*k).empty() || (*v).empty())
    {
        return false;
    }
    return true;
}